/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.figures;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;

import com.cea.papyrus.core.PapyrusPlugin;

/**
 * to rearchitecture.
 */
public class EnumerationFigure extends NodeFigure {

	/**
	 * 
	 */
	private Figure contentPane;

	/**
	 * 
	 */
	private ContainerFigure literalsContent;
	
	/**
	 * 
	 */
	private Color borderColor=PapyrusPlugin.colorManager.get(new RGB(157,124,47));

	/**
	 * 
	 */
	public EnumerationFigure() {
		ToolbarLayout layout = new ToolbarLayout();

		setLayoutManager(layout);
		layout.setSpacing(0);

		setOpaque(true); // non-transparent figure
		//setBorder( new LineBorder(ColorConstants.black));
		setBorder( new LineBorder(borderColor));
		//setBackgroundColor(ColorConstants.yellow);
		setBackgroundColor(PapyrusPlugin.colorManager.get(new RGB(248,249,214)));//yellow

		// The area accepting inner figures.
		createContentPane();	
	}

	/**
	 * 
	 * 
	 * @param literalContent 
	 */
	public void addFeatureContainer(ContainerFigure literalContent){
		this.literalsContent=literalContent;
	}

	/**
	 * 
	 * 
	 * @return 
	 */
	public ContainerFigure getLiteralsContent(){
		return literalsContent;
	}

	/**
	 * Get the inner figure accepting childs figure.
	 * 
	 * @return 
	 */
	public IFigure getContentPane()
	{
		return contentPane;	
	}

	/**
	 * 
	 */
	protected void createContentPane()
	{
		contentPane = new Figure();
		ToolbarLayout layout = new ToolbarLayout();
		layout.setVertical(true);
		contentPane.setLayoutManager(layout);
		add(contentPane);

	}

	/**
	 * 
	 * 
	 * @param rect 
	 */
	@Override
	public void setBounds(Rectangle rect) {
		super.setBounds(rect);
		int literalsHeight=rect.height;;


		if (getLiteralsContent()!=null){
			if (getStereotypesLabel() != null)
			{literalsHeight=literalsHeight-getStereotypesLabel().getPreferredSize().height;}
			if (getQualifiedNameLabel() != null)
			{literalsHeight=literalsHeight-getQualifiedNameLabel().getPreferredSize().height;}


			literalsHeight=literalsHeight-getNameLabel().getPreferredSize().height;


			getLiteralsContent().setPreferredSize(30, literalsHeight);

		}
	}
	
	/**
	 * 
	 * 
	 * @param graphics 
	 */
	@Override
	public void paint (Graphics graphics) {
		super.paint (graphics);
		Figure f;
		Rectangle rect;
		f = getLiteralsContent();
		if (f!=null){
			rect = f.getBounds();
			graphics.setForegroundColor(getBorderColor());
			graphics.setBackgroundColor(getBorderColor());
			graphics.drawLine(rect.x, rect.y, rect.x+rect.width, rect.y);

			graphics.drawLine(rect.x, rect.y+rect.height, rect.x+rect.width, rect.y+rect.height);
		}
	}

	/**
	 * 
	 * 
	 * @param b 
	 */
	public void setAbstract(boolean b){
		if (b) {
			FontData[] font={new FontData("Arial", 10, SWT.ITALIC|SWT.BOLD)};
			this.getNameLabel().setFont(PapyrusPlugin.fontManager.get(font));//italic
		} else {
			FontData[] font={new FontData("Arial", 10, SWT.BOLD)};
			this.getNameLabel().setFont( PapyrusPlugin.fontManager.get(font));
		}
	}
} 
